﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using DevTeam;

using System;
using System.Drawing;

namespace ConfExpert.Forms.Depo.OverProduction
{
    public partial class OPDurumRaporu : XForm
    {
        bool GP;
        public OPDurumRaporu(bool GP)
        {
            InitializeComponent();
            this.GP = GP;
        }

        private void OverProductionTum_Load(object sender, EventArgs e)
        {
            txtInfo.Caption = "Açık OP Girişleri";
            gvMT.Init("GetOP2", (GP ? 6 : 5), 0, "Kumas");
            gvMT.AddDetailGrid(gvTop, "CikilanCustomerId");
            gvTop.AddColumn("MT", typeof(int), "Iif(MusteriKullanacakMi is null, 1, 0)");
            gvTop.AddColumn("K", typeof(int), "Iif(MusteriKullanacakMi='E' OR MusteriKullanacakMi='H', 1, 0)");
            gvMT.AddColumn("MT", typeof(int), "SUM(Child({FK}).MT)");
            gvMT.AddColumn("K", typeof(int), "SUM(Child({FK}).K)");
            gvMT.AddColumn("TopAdedi", typeof(int), "COUNT(Child({FK}).YeniRollId)");
            gvMT.AddColumn("ToplamMt", typeof(int), "SUM(Child({FK}).NewQty)");
            gvMT.FormatAsNumber(0, "MT", "K");
            gvMT.AddSummary("TopAdedi", "ToplamMt", "MT", "K");

            gvTop.MakeColumnInvisible("MT", "K", "ProductId");
            gvTop.AddSummary("NewQty");

            gvTop.Columns["MTId"].ColumnEdit = RI(Rp.V_User);
            gvTop.Columns["CikilanAtelyeId"].ColumnEdit = RI(Rp.Atelye);
            gvTop.Columns["CikilanCustomerId"].ColumnEdit = gvMT.Columns["CikilanCustomerId"].ColumnEdit = RI(Rp.V_Customer);
            gvTop.Columns["CikilanBrandId"].ColumnEdit = RI(Rp.Brand);
            gvTop.Columns["CikilanSezonId"].ColumnEdit = RI(Rp.Sezon);

            if (GP)
            {
                
                this.Text = "GP_OP";
                splitContainerControl2.PanelVisibility = SplitPanelVisibility.Panel2;
                gvMT.FocusedRowHandle = gvMT.LocateByValue("CikilanCustomerId", 20);
                gvTop.SetCaptions("NewQty:Dönen Miktar");
                gvTop.FormatAsDate("CikisTarihi", "GirisTarihi", "KontrolTarihi", "AyrimTarihi");
            }
            else
                gvTop.Columns["CikilanVendorId"].ColumnEdit = RI(Rp.Vendor);


            //gvTop.SetCaptions(
            //    "LastSeenQty:Son Bilinen Miktar"
            //    , "RfidSet:RFID Yazıldı"
            //    , "BarkodSet:Barkod Basıldı"
            //    , "CikisTipiId:Çıkış Tipi"
            //    );

            gvMT.RowCellStyle += new RowCellStyleEventHandler(gvOP_RowCellStyle);
            gvTop.RowCellStyle += new RowCellStyleEventHandler(gvOP_RowCellStyle);
            gvMT.BestFitColumns();
            gvTop.BestFitColumns();

        }


        void gvOP_RowCellStyle(object sender, RowCellStyleEventArgs e)
        {
            switch (e.Column.FieldName)
            {
                case "NewQty":
                case "ToplamMt":
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                    break;
            }

        }

    }
}